package com.situ.day30;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolDemo1 {
    public static void main(String[] args) {
        //一池五线程
        ExecutorService threadPool = Executors.newFixedThreadPool(5); //5个窗口
        //一池一线程
        //ExecutorService threadPool = Executors.newSingleThreadExecutor(); //一个窗口
        //一池可扩容线程
        //ExecutorService threadPool = Executors.newCachedThreadPool();
        //10个顾客请求
        try {
            for (int i = 1; i <=10; i++) {
                final int index = i;
                //执行
                threadPool.execute(new Runnable() {
                    @Override
                    public void run() {
                        System.out.println(Thread.currentThread().getName()+" 为第"+index+"个客户办理业务");
                    }
                });
            }
        }catch (Exception e) {
            e.printStackTrace();
        }finally {
            //关闭
            threadPool.shutdown();
        }
    }
}
